//
//  JingXuanShouYe_TableViewCell.m
//  iBook
//
//  Created by apple on 15/1/20.
//  Copyright (c) 2015年 wikiflyer. All rights reserved.
//

#import "JingXuanShouYe_TableViewCell.h"
#import "CommonFunc.h"


#define MRScreenHeight     CGRectGetHeight([UIScreen mainScreen].applicationFrame)
#define MRScreenWidth      CGRectGetWidth([UIScreen mainScreen].applicationFrame)

@implementation JingXuanShouYe_TableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (id)homeCellCellOwner:(id)owner {
    if (!owner) {
        return nil;
    }
    NSArray *nibEles = [[NSBundle mainBundle] loadNibNamed:@"JingXuanShouYe_TableViewCell" owner:owner options:nil];
    for (id cellObject in nibEles) {
        if ([cellObject isKindOfClass:[JingXuanShouYe_TableViewCell class]]) {
            return (JingXuanShouYe_TableViewCell *)cellObject;
        }
    }
    return nil;
}
-(void)initWithSome:(NSMutableArray *)theArray thetitle:(NSDictionary *)theTitle{
    
    self.delegate=self;
    
    _arrayShuJiJieShou=[[NSMutableArray alloc] init];
    [_arrayShuJiJieShou addObjectsFromArray:theArray];
    _theQuanBuXianShiID=[theTitle objectForKey:@"hid"];
    
    UILabel * lable1X=[[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 30)];
    lable1X.text=[NSString stringWithFormat:@"%@",[theTitle objectForKey:@"hnm"]];
    [self addSubview:lable1X];
    
    UIButton * btn1=[UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame=CGRectMake(MRScreenWidth-100, 15, 80, 25);
    btn1.titleLabel.font=[UIFont systemFontOfSize:14];
    [btn1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [btn1 setTitle:@"显示全部" forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(goBtn1) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn1];
    
    UIScrollView * myScrollV=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, MRScreenWidth, 220)];
    myScrollV.showsVerticalScrollIndicator = FALSE;
    myScrollV.showsHorizontalScrollIndicator = FALSE;
    myScrollV.contentSize=CGSizeMake(15+(theArray.count-1)*95+80+15, 220);
    for (int a=0; a<theArray.count; a++) {
        UIButton * myBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        myBtn.frame=CGRectMake(15+a*95, 5, 80, 180);
        myBtn.tag=100+a;
        myBtn.titleLabel.font=[UIFont systemFontOfSize:14];
        [myBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [myBtn addTarget:self action:@selector(goBtn:) forControlEvents:UIControlEventTouchUpInside];
        [myScrollV addSubview:myBtn];
        
        
        
        NSData* dataImage = [CommonFunc dataWithBase64EncodedString:[NSString stringWithFormat:@"%@",[theArray[a] objectForKey:@"pic"]]];
        UIImageView * imageV=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 120)];
        imageV.image=[UIImage imageWithData:dataImage];
        [myBtn addSubview:imageV];
        
        UILabel * labelx1=[[UILabel alloc] initWithFrame:CGRectMake(0, 120+15, 80, 15)];
        labelx1.text=[theArray[a] objectForKey:@"onm"];
        labelx1.font=[UIFont systemFontOfSize:12];
        [myBtn addSubview:labelx1];
        
        UILabel * lablex2=[[UILabel alloc] initWithFrame:CGRectMake(0, 120+30, 80, 30)];
        lablex2.font=[UIFont systemFontOfSize:12];
        lablex2.numberOfLines=0;
        lablex2.text=[theArray[a] objectForKey:@"ath"];
        [myBtn addSubview:lablex2];
    }
    [self addSubview:myScrollV];
}
#pragma mark - btn
-(void)goBtn:(UIButton *)sender{
    _theIDShuJi=[_arrayShuJiJieShou[sender.tag-100] objectForKey:@"oid"];
    if ([_delegate respondsToSelector:@selector(JingXuanShouYe_TableViewCell_Detegate:theID:)]) {
        [_delegate JingXuanShouYe_TableViewCell_Detegate:self theID:_theIDShuJi];
    }
    
    
}
-(void)goBtn1{
    NSLog(@"显示全部");
    if ([_delegate respondsToSelector:@selector(JingXuanShouYe_TableViewCell_DetegateQuanBu:theID:)]) {
        [_delegate JingXuanShouYe_TableViewCell_DetegateQuanBu:self theID:_theQuanBuXianShiID];
    }
}


@end
